package com.yejign.quartzdemo;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.impl.matchers.EverythingMatcher;

public class Demo3 {
    public static void main(String[] args) throws Exception{

        JobDetail jobDetail = JobBuilder.newJob(TestJob.class)
                .withIdentity("testJob", "testJobGroup")
                .build();

        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("testTrigger", "testTriggerGroup")
                .startNow()
                .withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(5))
                .build();



        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

        // 创建并注册一个全局的Job Listener
        scheduler.getListenerManager().addJobListener(new MyJobListener(), EverythingMatcher.allJobs());
        scheduler.getListenerManager().addTriggerListener(new MyTriggerListener());
        scheduler.getListenerManager().addSchedulerListener(new MySchedulerListener());

        scheduler.scheduleJob(jobDetail, trigger);

        // 5，开启任务
        scheduler.start();
    }
}
